package com.itheima.homework;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class InputStreamTest{
    public static void main(String[] args) throws Exception {
        read1();
        System.out.println("======");
        read2();
    }

    public static void read1() throws Exception {
        //TODO 一次读取一个字节
        FileInputStream fis = new FileInputStream("D:/file01.txt");
        int byt ;
        while((byt =fis.read()) != -1)
            System.out.print((char)byt);
        System.out.println();
        fis.close();
    }
    public static void read2() throws Exception {
        //TODO 一次读取多个字节
        FileInputStream fis = new FileInputStream("D:/file01.txt");
        byte[] bytes = new byte[5];
        int len;
        while ((len = fis.read(bytes))!=-1 )
            System.out.print(new String(bytes,0,len));
        fis.close();
    }
}
